from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .config import settings
from .db import Base, engine
from .routers import auth, users, issues, groups, tags, knowledge, reviews, stats, folders
from .routers import knowledge_folders, review_folders
from .routers import exams

# IMPORTANT: import models before create_all so that tables are registered
from . import models  # noqa: F401
Base.metadata.create_all(bind=engine)

app = FastAPI(title="Issue Management API", version="1.0.0")

app.add_middleware(
    CORSMiddleware,
    allow_origins=settings.CORS_ORIGINS,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
app.include_router(users.router, prefix="/api/users", tags=["users"])
app.include_router(issues.router, prefix="/api/issues", tags=["issues"])
app.include_router(groups.router, prefix="/api/groups", tags=["groups"])
app.include_router(tags.router, prefix="/api/tags", tags=["tags"])  # type: ignore
app.include_router(knowledge.router, prefix="/api/knowledge", tags=["knowledge"])
app.include_router(reviews.router, prefix="/api/reviews", tags=["reviews"])
app.include_router(stats.router, prefix="/api/stats", tags=["stats"])
app.include_router(folders.router, prefix="/api/folders", tags=["folders"])
app.include_router(knowledge_folders.router, prefix="/api/knowledge-folders", tags=["knowledge-folders"])
app.include_router(review_folders.router, prefix="/api/review-folders", tags=["review-folders"])
app.include_router(exams.router, prefix="/api/exams", tags=["exams"])
from .routers import brush
app.include_router(brush.router, prefix="/api/brush", tags=["brush"])
